<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">

	<ui:define name="content">
		<f:event type="preRenderView" listener="#{ojtController.beforeAdd}" />
		<div class="title ui-widget-header ui-corner-all">
			<h:panelGrid style="margin:auto;">
		AGREGAR OJT
		</h:panelGrid>

		</div>
		<h:form id="formAdd">
			<h:panelGrid style="margin:auto;">

				<h:panelGrid style="margin:auto;text-align:center;">
					<p:messages id="messages" ></p:messages>
				</h:panelGrid>

				<h:panelGrid columns="2" id="panelAdd">

					<h:panelGrid>
						<h:panelGrid columns="4">
							<p:outputLabel value="Documento de identidad"></p:outputLabel>
							<p:inputText id="candidateDocumentNumber"
								value="#{ojtController.candidateDocumentNumberSearch}"></p:inputText>
							<p:commandButton
								actionListener="#{ojtController.searchTrainingByDocumentNumber}"
								value="Buscar capacitaciones"
								process="@this :formAdd:candidateDocumentNumber"
								update=":formAdd:trainingsTable :formAdd:trainingId :formAdd:messages">
							</p:commandButton>
							<p:outputLabel id="trainingId"
								value="Capacitación seleccionada: #{ojtController.trainingSelected!=null?ojtController.trainingSelected.id:''}">
							</p:outputLabel>
						</h:panelGrid>

						<p:dataTable value="#{ojtController.trainings}" var="t"
							rowKey="#{t.id}" id="trainingsTable" selectionMode="single"
							selection="#{ojtController.trainingSelected}">

							<p:ajax event="rowSelect" update=":formAdd:trainingId" />
							<p:ajax event="rowUnselect" update=":formAdd:trainingId" />

							<p:column headerText="ID">
								<h:outputText value="#{t.id}"></h:outputText>
							</p:column>

							<p:column headerText="DNI">
								<h:outputText value="#{t.interview.candidate.documentNumber}"></h:outputText>
							</p:column>

							<p:column headerText="Nombres">
								<h:outputText value="#{t.interview.candidate.firstname}"></h:outputText>
							</p:column>

							<p:column headerText="Apellidos">
								<h:outputText value="#{t.interview.candidate.lastname}"></h:outputText>
							</p:column>

							<p:column headerText="Fecha de Capacitación">
								<h:outputText value="#{t.trainingAt}">
									<f:convertDateTime pattern="dd-MM-yyyy" />
								</h:outputText>
							</p:column>

							<p:column headerText="Capacitador">
								<h:outputText
									value="#{t.trainer.firstname} #{t.trainer.lastname}"></h:outputText>
							</p:column>

							<p:column headerText="Estado">
								<h:outputText value="#{t.trainingState.name}"></h:outputText>
							</p:column>

							<p:column headerText="Comentarios">
								<h:outputText value="#{t.comment}"></h:outputText>
							</p:column>

						</p:dataTable>

					</h:panelGrid>
					<h:panelGrid columns="2">

						<p:outputLabel value="Comentarios:"></p:outputLabel>
						<p:inputTextarea value="#{ojtController.ojtSelected.comment}"
							rows="4" cols="30"></p:inputTextarea>

					</h:panelGrid>

				</h:panelGrid>

				<h:panelGrid style="margin:auto;text-align:center;">
					<p:commandButton action="#{ojtController.add}" value="Agregar" ajax="false">
					</p:commandButton>
				</h:panelGrid>
			</h:panelGrid>
		</h:form>
	</ui:define>

</ui:composition>
</html>
